package com.xucy.springboot.designmodel.creational.prototype.deep;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * @Author xucy
 * @Date 2019-07-17 17:47
 * @Description 深克隆
 **/

@Getter
@Setter
public class DeepProtoType implements Cloneable{

    Date date;

    String msg;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        DeepProtoType deepProtoType=(DeepProtoType)super.clone();
        //需要对引用型属性进行克隆，这样才不会影响之前的对象，即深克隆模式
        deepProtoType.setDate((Date)deepProtoType.getDate().clone());


        return deepProtoType;
    }

    @Override
    public String toString() {
        return "date"+this.getDate()+"msg"+this.getMsg()+super.toString();
    }
}
